package com.yusheng.utils;

import com.alibaba.fastjson2.JSON;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.List;

@SuppressWarnings("all")
public class JsonUtils {

    public static String readDataFromJson(String filePath) throws Exception {
        return FileUtils.readFileToString(new File(filePath), "UTF-8");
    }

    public static void writeDataJson(String filePath, List list) throws Exception {
        File file = new File(filePath);
        if (!file.exists()) {
            file.getParentFile().mkdir();
            file.createNewFile();
        }
        PrintStream ps = new PrintStream(new FileOutputStream(file));
        ps.append(JSON.toJSONString(list));
    }

}
